Avoid diagnostics for gcc-11 false positive out of bounds accesses
authorKalev Lember <klember@redhat.com>
Sun, 10 Jan 2021 08:35:40 +0000 (09:35 +0100)
committerKalev Lember <klember@redhat.com>
Mon, 11 Jan 2021 16:19:36 +0000 (17:19 +0100)
This is a patch by Jeff Law <law@redhat.com> done in downstream Fedora
to fix the build with gcc 11.

gtk/gtktextchild.c
gtk/gtktextsegment.c

index 4d5e30e44fceae22a98ca70fcba5e4b67d04bec8..915b9917dd49c52226d888d0f5f364b0c400b3ce 100644 (file)
@@ -169,6 +169,12 @@ const GtkTextLineSegmentClass gtk_text_paintable_type = {
 GtkTextLineSegment *
 _gtk_paintable_segment_new (GdkPaintable *paintable)
 {
+  /* gcc-11 issues a diagnostic here because the size allocated
+     for SEG does not cover the entire size of a GtkTextLineSegment
+     and gcc has no way to know that the union will only be used
+     for limited types and the additional space is not needed.  */
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Warray-bounds"
   GtkTextLineSegment *seg;
   guint flags;
 
@@ -204,6 +210,7 @@ _gtk_paintable_segment_new (GdkPaintable *paintable)
   g_object_ref (paintable);
 
   return seg;
+#pragma GCC diagnostic pop
 }
 
 
@@ -280,6 +287,12 @@ const GtkTextLineSegmentClass gtk_text_child_type = {
 GtkTextLineSegment *
 _gtk_widget_segment_new (GtkTextChildAnchor *anchor)
 {
+  /* gcc-11 issues a diagnostic here because the size allocated
+     for SEG does not cover the entire size of a GtkTextLineSegment
+     and gcc has no way to know that the union will only be used
+     for limited types and the additional space is not needed.  */
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Warray-bounds"
   GtkTextLineSegment *seg;
 
   seg = g_slice_alloc (WIDGET_SEG_SIZE);
@@ -303,6 +316,7 @@ _gtk_widget_segment_new (GtkTextChildAnchor *anchor)
   g_object_ref (anchor);
   
   return seg;
+#pragma GCC diagnostic pop
 }
 
 void
index a202ab603cddc731e6ac9d701cb7d3e2ebb4d667..0680b73cfa16a7836d940b8890206c652a892ff0 100644 (file)
@@ -425,6 +425,12 @@ char_segment_check_func (GtkTextLineSegment *segPtr, GtkTextLine *line)
 GtkTextLineSegment*
 _gtk_toggle_segment_new (GtkTextTagInfo *info, gboolean on)
 {
+  /* gcc-11 issues a diagnostic here because the size allocated
+     for SEG does not cover the entire size of a GtkTextLineSegment
+     and gcc has no way to know that the union will only be used
+     for limited types and the additional space is not needed.  */
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Warray-bounds"
   GtkTextLineSegment *seg;
 
   seg = g_slice_alloc (TSEG_SIZE);
@@ -440,6 +446,7 @@ _gtk_toggle_segment_new (GtkTextTagInfo *info, gboolean on)
   seg->body.toggle.inNodeCounts = 0;
 
   return seg;
+#pragma GCC diagnostic pop
 }
 
 void